package _mst;

import _object.ListNode;

import java.util.HashSet;
import java.util.Set;

/**
 * 面试题 02.01. 移除重复节点
 */
public class T0201 {
    public ListNode removeDuplicateNodes(ListNode head) {
        Set<Integer> set = new HashSet<>();
        ListNode dummy = new ListNode(-1, head);
        while (dummy.next != null) {
            if (set.contains(dummy.next.val)) {
                dummy.next = dummy.next.next;
                continue;
            } else set.add(dummy.next.val);
            dummy = dummy.next;
        }
        return head;
    }
}
